//
//  LNode.m
//  ProjectL
//
//  Created by Nguyen Tan Loc on 8/16/13.
//  Copyright (c) 2013 Nguyen Tan Loc. All rights reserved.
//

#import "LNode.h"

@implementation LNode
@synthesize _nextNode = mNextNode;

-(id) init
{
    if (self = [super initWithSpriteFrameName:[self getSpriteFrameName]])
    {
        [self createBody];
    }
    
    return self;
}

-(void) createBody
{
    b2BodyDef bodyDef;
    bodyDef.type = b2_dynamicBody;
    bodyDef.position.Set(0, 0);
    
    _b2Body = PhysicSystem::getInstance()->mWorld->CreateBody(&bodyDef);
    
    b2CircleShape shape;
    shape.m_radius = (self.contentSize.width / 2) / PTM_RATIO;
    
    b2FixtureDef fixtureDef;
    fixtureDef.shape = &shape;
    fixtureDef.filter.categoryBits = [self getObjectType];
    fixtureDef.filter.maskBits = 0;
    fixtureDef.isSensor = true;
    _b2Body->CreateFixture(&fixtureDef);
    
    [self setPTMRatio:PTM_RATIO];
    _b2Body->SetUserData(self);
}

-(void) addActions:(NSArray *)actions
{
    mListAction = [actions retain];
}

-(void) startAction
{
    if (mListAction != nil)
    {
        for (int i = 0; i < mListAction.count; i++)
        {
            [self runAction:[mListAction objectAtIndex:i]];
        }
    }
}

-(void) stopAction
{
    [self stopAllActions];
}

-(OBJECT_TYPE) getObjectType
{
    return eO_BOMB;
}

-(NSString *) getSpriteFrameName
{
    return SFN_LNODE;
}

-(void) dealloc
{
    [super dealloc];
    CCLOG(@"LNode dealloc!");
}

@end
